//
//  WTMessageFactory.m
//  WTLiveSDKDemo
//
//  Created by ben on 16/9/26.
//  Copyright © 2016年 ben. All rights reserved.
//

#import "WTMessageFactory.h"
#import "WTLiveSDKHeaders.h"


@implementation WTMessageFactory

+ (NSDictionary*)chatMessageRemoteExt{
 
    return @{@"avatar":WTConfig.avatar,@"name":WTConfig.nick,@"net_ease_id":WTConfig.net_accid,@"user_id":WTConfig.user_id,@"level":@(WTConfig.level)};
}

+ (NSDictionary*)enterChatRoomRemoteExt{
    return  @{@"net_ease_id":WTConfig.net_accid,@"icon":WTConfig.avatar,@"level":@(WTConfig.level),@"nick":WTConfig.nick};
}

+ (NSDictionary*)chatRoomMessageRemoteExt{
    
    return @{@"type":@(WTChatRoomMessageText),@"name":WTConfig.nick,@"net_ease_id":WTConfig.net_accid,@"user_id":WTConfig.user_id,@"level":@(WTConfig.level),@"avatar":WTConfig.avatar};
}

+ (NSDictionary*)chatRoomDanMuMessageRemoteExt{
    
    return  @{@"type":@(WTChatRoomMessageDanmuText),@"name":WTConfig.nick,@"net_ease_id":WTConfig.net_accid,@"user_id":WTConfig.user_id};
}

+ (NSDictionary*)chatRoomExitRemoteExt{
    return @{@"type":@(WTChatRoomMessageExit),@"net_ease_id":WTConfig.net_accid};
}

+ (NSDictionary*)chatRoomEnterRemoteExt{
    return @{@"type":@(WTChatRoomMessageEnter),@"name":WTConfig.nick,@"net_ease_id":WTConfig.net_accid,@"level":@(WTConfig.level),@"avatar":WTConfig.avatar};
}

+ (NSDictionary*)giftRemoteExt:(NSDictionary*)giftInfo{
    
    NSMutableDictionary* RemoteExt = [[NSMutableDictionary alloc] initWithCapacity:0];
    NSDictionary* baseInfo = @{@"type":@(WTChatRoomMessageSendGift),@"name":WTConfig.nick,@"icon":WTConfig.avatar,@"user_id":WTConfig.user_id,@"net_ease_id":WTConfig.net_accid};
    [RemoteExt addEntriesFromDictionary:baseInfo];
    [RemoteExt addEntriesFromDictionary:giftInfo];
    return RemoteExt;
}


+ (NSDictionary*)ownerEnterRemoteExt{
    return @{@"type":@(WTChatRoomMessageOwnerEnter)};
}

+ (NSDictionary*)ownerLeaveRemoteExt{
    
    return @{@"type":@(WTChatRoomMessageOwnerLeave)};
}


+ (NSDictionary*)exitLiveRemoteExt{
    return @{@"type":@(WTChatRoomMessageExitLive)};
}


+ (WTBaseMessageModel *)chatMessageModelWithRemoteExt:(NSDictionary *)RemoteExt{
    
    if(!RemoteExt){
        return nil;
    }
    WTBaseMessageModel* model = [[WTBaseMessageModel alloc] init];
    model.chat_message_avtar_icon = RemoteExt[@"avatar"];
    model.chat_message_avtar_name = RemoteExt[@"name"];
    model.chat_message_net_ease_id = RemoteExt[@"net_ease_id"];
    model.sessionType = NIMSessionTypeP2P;
    return model;
}

+ (WTBaseMessageModel *)chatRoomMessageModelWithRemoteExt:(NSDictionary *)RemoteExt{

    if(!RemoteExt){
        return nil;
    }
    WTBaseMessageModel* model = [[WTBaseMessageModel alloc] init];
    WTChatRoomMessageType type = [RemoteExt[@"type"] integerValue];
    model.chat_room_message_messagetype = type;
    model.sessionType = NIMSessionTypeChatroom;
    model.chat_room_message_net_ease_id = RemoteExt[@"net_ease_id"];
    model.chat_room_message_user_id = RemoteExt[@"user_id"];
    model.chat_room_message_avtar_name = RemoteExt[@"name"];
    model.chat_room_message_avtar_icon = RemoteExt[@"avatar"];
    if(!model.chat_room_message_avtar_icon){
        model.chat_room_message_avtar_icon = RemoteExt[@"icon"];
    }
    model.chat_room_message_level = [RemoteExt[@"level"] integerValue];
    
    if(type == WTChatRoomMessageSendGift){
        model.chat_room_message_gift_model = [[WTChatRoomGiftModel alloc] init];
        model.chat_room_message_gift_model.gift_id = RemoteExt[@"gift_type"];
        model.chat_room_message_gift_model.gift_name = RemoteExt[@"gift_name"];
        model.chat_room_message_gift_model.gift_count = [RemoteExt[@"gift_count"] integerValue];
        model.chat_room_message_gift_model.gift_price = [RemoteExt[@"gift_price"] integerValue];
        model.chat_room_message_gift_model.gift_image_url = RemoteExt[@"gift_icon"];
        model.chat_room_message_gift_model.gift_scale = [RemoteExt[@"gift_scale"] integerValue];
        model.chat_room_message_gift_model.gift_sender_name = RemoteExt[@"name"];
        model.chat_room_message_gift_model.gift_sender_avatar = RemoteExt[@"icon"];
        
    }else if(type == WTChatRoomMessageEnter){
        model.chat_room_message_text = @"来了，欢迎~";
    }else if(type == WTChatRoomMessageFocus){
        model.chat_room_message_text = @"关注了主播";
    }
    return model;
    
}
@end
